﻿//************************************************************************************************
// Copyright © 2012 Steven M. Cohn. All Rights Reserved.
//
//************************************************************************************************

namespace Cookie.Baker
{
	using System;
	using System.Collections.Generic;
	using System.IO;
	using CookieChipper;
	using Microsoft.VisualStudio.TestTools.UnitTesting;


	[TestClass]
	public class CookieCacheProviderTests
	{

		[TestMethod]
		public void TestCacheProvider ()
		{
			try
			{
				int count = 0;
				using (var provider = new CookieCacheProvider())
				{
					Assert.IsNotNull(provider);
					Console.WriteLine("Provider path is [" + ((CookieCacheProvider)provider)._Path + "]");

					bool open = provider.Open();
					Assert.IsTrue(open);

					Cookie cookie;

					while ((cookie = provider.GetNext()) != null)
					{
						Console.WriteLine(cookie.Domain);
						count++;
					}
				}

				Assert.IsFalse(count == 0);
			}
			catch (FileNotFoundException)
			{
			}
		}


		[TestMethod]
		public void TestHistoryCacheProvider ()
		{
			string path = Path.Combine(
				Environment.GetFolderPath(Environment.SpecialFolder.InternetCache),
				@"Content.IE5\index.dat");

			//path = @"C:\Users\cohns\AppData\Local\Temp\Cookies\index.dat";
			path = Path.Combine(CookieCacheProvider.GetDirectoryPath(), "index.dat");
	
			Assert.IsTrue(File.Exists(path));

			int count = 0;
			using (var provider = new CookieCacheProvider(path))
			{
				Assert.IsNotNull(provider);
				Console.WriteLine("Provider path is [" + ((CookieCacheProvider)provider)._Path + "]");

				bool open = provider.Open();
				Assert.IsTrue(open);

				Cookie cookie;
				while ((cookie = provider.GetNext()) != null)
				{
					Console.WriteLine(cookie.Domain);
					count++;
				}
			}

			Assert.IsFalse(count == 0);
		}
	}
}
